<template>
  <section class="craftsman-main">
    <el-collapse-transition>
      <section v-show="searchshow" class="main-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model.trim="listQuery.name" placeholder="输入姓名搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <section class="search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <!--          <span class="search-more" @click="searchshow = !searchshow">
            更多筛选条件
            <i class="el-icon-arrow-down" />
          </span>-->
        </section>
      </section>
    </el-collapse-transition>
    <!--
    <el-collapse-transition>
      <section v-show="!searchshow" class="main-search separate">
        <section class="search-inner">
          <el-row>
            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">姓名</div>
                <el-input v-model.trim="search.name" style="width: 90%" class="filter-item" placeholder="请输入姓名搜索" />
              </section>
            </el-col>

            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">所属单位</div>
                <el-input v-model.trim="search.deptName" style="width: 90%" class="filter-item" placeholder="请输入所属单位搜索" />
              </section>
            </el-col>
            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">标签</div>
                <el-input v-model.trim="search.labelsValue" style="width: 90%" class="filter-item" placeholder="请输入标签搜索" />
              </section>
            </el-col>

          </el-row>
          <el-row style="margin-top: 20px;">
            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">所属地区</div>
                <el-cascader ref="area" v-model="search.ssdq" style="width:90%" clearable :props="areaProps" />
              </section>
            </el-col>
            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">政治面貌</div>
                <el-select v-model="search.politicCountenance" style="width: 90%" clearable placeholder="请选择">
                  <el-option v-for="item in dict.ZZMM" :key="item.dictValue" :value="item.dictValue" :label="item.dictName" />
                </el-select>
              </section>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">分类</div>
                <el-cascader ref="classify" v-model="search.classifyIdValue" style="width:90%" clearable :props="classifyProps" :options="classifyOptions" />
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">性别</div>
                <el-radio-group v-model="search.sex" style="margin-top: 20px;">
                  <el-radio label="">不限</el-radio>
                  <el-radio label="MAN">男</el-radio>
                  <el-radio label="WOMAN">女</el-radio>
                </el-radio-group>
              </section>
            </el-col>
          </el-row>
        </section>
        <section class="search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <span class="search-more" @click="searchshow = !searchshow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </section>
      </section>
    </el-collapse-transition>
-->

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>人物库</span>
      </section>
      <section class="main-buttons-btns" />
      <el-button style="margin-left: 10px" @click="handleCreate">新建</el-button>
      <el-button style="margin-left: 10px;" @click="handleSelectPlatform">选取SaaS平台人物 </el-button>
      <!--      <el-button style="margin-left: 10px" @click="handleImport">批量导入</el-button>
      <el-button style="margin-left: 10px" @click="handleMultiSet">批量设置</el-button>-->
    </section>
    <div class="classify-tab">
      <el-tabs v-model="activeTab" @tab-click="handleTabClick">
        <el-tab-pane v-for="(item, index) in dict.RWFL" :key="index" :label="item.dictName" :name="item.dictValue" />
      </el-tabs>
    </div>
    <section class="main-table">
      <v-table v-if="tag" ref="multipleTable" :list-loading="listLoading" :list="list" :filter-column="filtercolumn" :tag="tag" :source-arr="sourceArr">
        <el-table-column fixed="right" label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleRecord(scope.row)">档案</el-button>
            <el-button type="text" size="mini" @click="handleView(scope.row)">查看</el-button>
            <el-button
              v-if="scope.row.status !== 'GIPSTSTUS01' && !scope.row.isForce"
              type="text"
              size="mini"
              @click="handleUpdate(scope.row)"
            >编辑</el-button>
            <el-button v-if="scope.row.isForce !== 'SF01'" type="text" size="mini" @click="handleDelete(scope.row)">删除</el-button>
            <el-button v-if="scope.row.isForce !== 'SF01'" type="text" size="mini" @click="handlePublish(scope.row)">{{
              scope.row.publishStatus === 'GIPSTSTUS01' ? '取消发布' : '发布'
            }}</el-button>
            <el-button type="text" size="mini" @click="handleTop(scope.row)">{{ scope.row.isTop == 1 ? '取消置顶' : '置顶' }}</el-button>
            <!--            <el-button type="text" size="mini" @click="handleSet(scope.row)">设置</el-button>-->
            <!--            <el-button type="text" size="mini" @click="handleComment(scope.row.id)">评论</el-button>-->
            <el-button type="text" size="mini" @click="handleAddress(scope.row.id)">地址</el-button>
            <el-button
              v-if="scope.row.isForce === 'SF01'"
              type="text"
              size="mini"
              @click="handleSort(scope.row)"
            >修改排序</el-button>
          </template>
        </el-table-column>
      </v-table>
      <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
      <grade v-if="craftsmanStatus" :id="chooseItem.id" :obj="chooseItem" :type="setType" @closeSet="craftsmanStatus = false" />
      <record v-if="recordStatus" :id="chooseItem.id" @close="recordStatus = false" />
    </section>
    <el-dialog
      v-if="viewShow"
      v-el-drag-dialog
      title="查看"
      :close-on-click-modal="false"
      :visible.sync="viewShow"
      center
      width="1000px"
      @close="handleClose"
    >
      <el-tabs>
        <el-tab-pane label="基本信息">
          <el-row class="time-line">
            <el-col :span="12" class="view-item">
              <span class="view-label">个人封面：</span>
              <el-image
                style="width: 190px; height: auto;display: inline-block;vertical-align: top;"
                :src="(chooseItem.headImgURL || chooseItem.coverUrl)"
                :preview-src-list="[chooseItem.headImgURL,chooseItem.coverUrl]"
              />
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">姓名：</span>
              {{ chooseItem.name }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">分类：</span>
              {{ chooseItem.classifyIdName }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">人物类型：</span>
              {{ chooseItem.craftsmanTypeName }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">性别：</span>
              {{ chooseItem.sexName }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">政治面貌：</span>
              {{ chooseItem.politicCountenanceName }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">所属单位：</span>
              {{ chooseItem.deptName }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">所属行业：</span>
              {{ chooseItem.profession }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">所属国籍：</span>
              {{ chooseItem.nationality }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">地区：</span>
              {{ chooseItem.regionList.join('/') }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">{{ chooseItem.craftsmanType === 'RWFL_GJ' ? '口号：' : '语录：' }}</span>
              {{ chooseItem.slogan }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">标签：</span>
              {{ chooseItem.labelsValue }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">特殊状态：</span>
              {{ chooseItem.specialStatusValue }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">职务：</span>
              {{ chooseItem.position }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">职称：</span>
              {{ chooseItem.technicalTitle }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">国籍：</span>
              {{ chooseItem.nativePlace }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">学历：</span>
              {{ chooseItem.education }}
            </el-col>
            <el-col class="view-item" :span="12">
              <span class="view-label">类型：</span>
              {{ chooseItem.typeName }}
            </el-col>
            <el-col class="view-item" :span="24">
              <span class="view-label">简介：</span>
              <div style="margin-top: 10px" v-html="chooseItem.synopsis" />
            </el-col>
            <el-col class="view-item" :span="24">
              <span class="view-label">事迹：</span>
              <div v-html="chooseItem.content" />
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="档案信息">
          <el-row>
            <div>
              <el-button-group>
                <el-button size="samll" :autofocus="true" :type="color ? 'primary' : 'default'" @click="handleClick('now')">当前档案</el-button>
                <el-button size="samll" :type="color ? 'default' : 'primary'" @click="handleClick('delete')">已删除档案</el-button>
              </el-button-group>
            </div>
            <div v-if="isShowBox" class="isShowBox">
              暂无档案信息
            </div>
            <div v-else class="time-line">
              <el-timeline>
                <el-timeline-item v-for="item in archivesList" :key="item.id" :timestamp="setTime(item)" placement="top" :color="color">
                  <el-card class="record-container">
                    <h4>{{ item.recordTypeName }}</h4>
                    <p>{{ item.recordDesc }}</p>
                  </el-card>
                </el-timeline-item>
              </el-timeline>
            </div>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogUploadVisible"
      title="上传文件"
      center
      width="500px"
      @close="handleClosed"
    >
      <el-upload
        ref="upload"
        v-loading="loadingUpload"
        element-loading-text="正在上传请稍后"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
        :auto-upload="false"
        :on-success="uploadSuccess"
        :on-error="uploadError"
        :action="uploadaction"
        :headers="uploadHeaders"
        :data="uploadData"
        accept=".xls, .xlsx"
        class="upload-demo"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div slot="tip" class="el-upload__tip">
          只能上传.xls,.xlsx
          <el-button type="text" @click="handleDownload">下载模板</el-button>
        </div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" type="primary" @click="handleClosed">取消</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="submitUpload()">确认</el-button>
      </span>
    </el-dialog>
    <el-dialog
      v-el-drag-dialog
      title="修改排序"
      width="30%"
      :visible.sync="sortDialog"
      @close="cancelDialog"
    >
      <el-input
        v-model="form.sort"
        placeholder="请输入排序值"
        type="number"
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="cancelDialog">取 消</el-button>
        <el-button style="padding: 8px 30px;" type="primary" @click="handelUpdateSort">确 定</el-button>
      </span>
    </el-dialog>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import { getClassifyTree, queryPage, del, updateState, updateIsTop, getDictByCode, getAreaTree, get, updateSort } from '../api/index'
import permission from '@/directive/permission/index.js'
import Grade from '../components/grade'
import Record from '../components/record'
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
import vTable from '@/components/Table'
import { exportSign, importSign } from '@/utils/fileImportOrExportSign'
export default {
  name: 'CraftsmanMain',
  components: { Pagination, Grade, Record, vTable },
  directives: { permission, elDragDialog },
  data() {
    return {
      areaProps: {
        label: 'regionName',
        value: 'id',
        checkStrictly: true,
        lazy: true,
        lazyLoad(node, resolve) {
          getAreaTree({ parentId: (node.data && node.data.id) || -1 })
            .then((res) => {
              if (res.data.data.length > 0 && res.data.data[0].ptrees.split(',').length !== 4) {
                res.data.data.forEach((item) => {
                  item['leaf'] = false
                })
              } else {
                res.data.data.forEach((item) => {
                  item['leaf'] = true
                })
              }
              resolve(res.data.data)
            })
            .catch(() => {
              resolve([])
            })
        }
      },
      dict: {
        ZZMM: [], // 政治面貌
        RWFL: []
      },
      tag: '',
      expireTimeOption: {
        disabledDate(date) {
          // disabledDate 文档上：设置禁用状态，参数为当前日期，要求返回 Boolean
          return date.getTime() > Date.now()
        }
      },
      listQuery: {
        page: 1,
        limit: 10,
        name: ''
      },
      searchshow: true,
      search: {
        name: '',
        sex: '',
        politicCountenance: '',
        ssdq: '',
        labelsValue: '',
        classifyIdValue: '',
        deptName: ''
      },
      classifyProps: {
        label: 'classifyName',
        value: 'id',
        checkStrictly: true,
        emitPath: false
      },
      classifyOptions: [],
      activeTab: '',
      list: [],
      total: 0,
      listLoading: false,
      craftsmanStatus: false,
      viewShow: false,
      chooseItem: {
        regionList: []
      },
      setType: 'single',
      link: '/craftsman?bt=gjrw&i=',
      dsLink: '/manFull?id=',
      recordStatus: false, // 个人经历弹窗
      archivesList: [],
      isShowBox: false,
      sourceArr: ['coverUrl', 'headImgURL'],
      color: '',
      dialogUploadVisible: false,
      loadingUpload: false,
      uploadData: {},
      uploadaction: '/API-ENTERPRISE-BACKEND/backend/craftsmanLibrary/importCraftman',
      uploadHeaders: { ttsxbwqm: '', ttsxsjzc: '', ttsxyhcs: '' },
      form: {
        id: '',
        sort: ''
      },
      sortDialog: false
    }
  },
  created() {
    this.getClassifyOption()
    for (const key in this.dict) {
      this.getDict(key)
    }
  },
  methods: {
    handleSelectPlatform() {
      this.$router.push({
        path: '/contentRepository/craftsman/SelectCourse4platform',
        query: {
          activeTab: this.activeTab,
          tag: this.tag
        }
      })
    },
    /**
     * 获取字典
     */
    getDict(code) {
      return new Promise((resolve, reject) => {
        getDictByCode(code)
          .then((response) => {
            this.dict[code] = response.data.data && response.data.data.length > 0 ? response.data.data[0].list : []
            if (code === 'RWFL') {
              if (this.dict[code].length > 0) {
                if (this.$route.query.t) {
                  this.activeTab = this.$route.query.t
                } else {
                  this.activeTab = this.dict[code][0].dictValue
                }
                this.tag = this.activeTab === 'RWFL_GJ' ? 'characterlibrary' : 'characterlibrary-artist'
                this.getList()
              }
            }
          })
          .catch((error) => {
            reject(error)
          })
      })
    },
    setTime(item) {
      const startTime = [item.startYear, item.startMonth, item.startDay]
      const endTime = [item.endYear, item.endMonth, item.endDay]
      const formData = ['年', '月', '日']
      let startstr = ''
      let endstr = ''
      for (let i = 0; i < startTime.length; i++) {
        if (startTime[i]) {
          startstr += startTime[i] + formData[i]
        } else {
          break
        }
      }

      for (let i = 0; i < endTime.length; i++) {
        if (endTime[i]) {
          endstr += endTime[i] + formData[i]
        } else {
          break
        }
      }
      if (startstr.trim() === endstr.trim()) {
        return startstr
      }
      if (item.isUntil === '1') {
        return `${startstr}  至今`
      }
      return startstr && endstr ? startstr + ' 至 ' + endstr : startstr || endstr
    },
    /**
     * 获取分类
     */
    getClassifyOption() {
      return new Promise((resolve, reject) => {
        getClassifyTree({ classifyType: 'FLGL_GJRW', status: 'ZT01' })
          .then(({ data }) => {
            this.classifyOptions = data.data || []
            // this.activeTab = data.data[0].id
          })
          .catch((error) => {
            reject(error)
          })
      })
    },
    /**
     * 新建
     */
    handleCreate() {
      this.$router.push({ path: this.$filterPath('manage'), query: { type: 'c', t: this.activeTab }})
    },
    /**
     * 批量设置
     */
    handleMultiSet() {
      this.setType = 'multi'
      this.craftsmanStatus = true
    },
    handleRegionList(row) {
      const arr = []
      if (row.areaProvinceName) {
        arr.push(row.areaProvinceName)
      }
      if (row.areaCityName) {
        arr.push(row.areaCityName)
      }
      if (row.areaCountyName) {
        arr.push(row.areaCountyName)
      }
      return arr.join('/')
    },
    /**
     * 查看
     */
    handleView(row) {
      // console.log('this.chooseItemthis.chooseItem', this.chooseItem)
      Object.keys(this.chooseItem).forEach(key => (this.chooseItem[key] = ''))
      // console.log('111111', this.chooseItem)
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      this.coursewareInfo = row
      get({ id: row.id }).then((res) => {
        loading.close()
        this.chooseItem = Object.assign({ ...this.chooseItem }, { ...res.data.data })
        this.chooseItem.regionList = []

        if (res.data.data.areaProvinceName) {
          this.chooseItem.regionList.push(res.data.data.areaProvinceName)
        }
        if (res.data.data.areaCityName) {
          this.chooseItem.regionList.push(res.data.data.areaCityName)
        }
        if (res.data.data.areaCountyName) {
          this.chooseItem.regionList.push(res.data.data.areaCountyName)
        }
        this.color = '#e44d42'
        console.log(res, 566)
        this.archivesList = res.data.data.record || []
        this.isShowBox = this.archivesList < 1
        this.$nextTick(() => {
          this.viewShow = true
        })
      })
    },
    /**
     * 查看评论
     */
    handleComment(id) {
      this.$router.push({ path: this.$filterPath('comment'), query: { i: id }})
    },
    /**
     * 个人档案
     */
    handleRecord(row) {
      this.chooseItem = Object.assign({}, row)
      this.recordStatus = true
    },
    /**
     * 查看前端地址
     */
    handleAddress(id) {
      if (this.activeTab === 'RWFL_GJ') {
        this.$confirm(`链接地址为：${this.link}${id}<span style="color:red">注意：该链接只对已发布数据有效</span>`, '提示', {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '复制链接',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            const input = document.createElement('input')
            input.setAttribute('readonly', 'readonly')
            input.setAttribute('value', this.link + id)
            document.body.appendChild(input)
            input.select()
            if (document.execCommand('copy')) {
              document.execCommand('copy')
              this.$message({
                title: '成功',
                message: '复制成功！',
                type: 'success',
                duration: 1500
              })
            }
            document.body.removeChild(input)
          })
          .catch(() => {})
      } else {
        this.$confirm(`链接地址为：${this.dsLink}${id}<span style="color:red">注意：该链接只对已发布数据有效</span>`, '提示', {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '复制链接',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            const input = document.createElement('input')
            input.setAttribute('readonly', 'readonly')
            input.setAttribute('value', this.dsLink + id)
            document.body.appendChild(input)
            input.select()
            if (document.execCommand('copy')) {
              document.execCommand('copy')
              this.$message({
                title: '成功',
                message: '复制成功！',
                type: 'success',
                duration: 1500
              })
            }
            document.body.removeChild(input)
          })
          .catch(() => {})
      }
    },
    /**
     * 编辑
     */
    handleUpdate(row) {
      this.$router.push({ path: this.$filterPath('manage'), query: { i: row.id, type: 'u' }})
    },
    /**
     * 发布/取消发布
     */
    handlePublish(row) {
      this.$confirm(row.publishStatus === 'GIPSTSTUS01' ? '确认取消发布？' : '确认发布？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          updateState({ id: row.id, publishStatus: row.publishStatus === 'GIPSTSTUS01' ? 'GIPSTSTUS02' : 'GIPSTSTUS01' }).then((res) => {
            if (res.data.code == '200') {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.getList()
            }
          })
        })
        .catch(() => {})
    },
    /**
     * 置顶/取消置顶
     */
    handleTop(row) {
      this.$confirm(row.isTop === 1 ? '确认取消置顶？' : '确认置顶？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          updateIsTop({ id: row.id, isTop: row.isTop === 1 ? 0 : 1 }).then((res) => {
            if (res.data.code === '200') {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.getList()
            }
          })
        })
        .catch(() => {})
    },
    /**
     * 设置
     */
    handleSet(row) {
      this.setType = 'single'
      this.chooseItem = Object.assign({}, row)
      this.craftsmanStatus = true
    },
    /**
     * 选项卡切换
     */
    handleTabClick(tab, event) {
      this.listQuery.page = 1
      if (this.activeTab === 'RWFL_GJ') {
        this.tag = 'characterlibrary'
      } else {
        this.tag = 'characterlibrary-artist'
      }
      this.getList()
    },
    handleDelete(row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          return new Promise((resolve, reject) => {
            del({ id: row.id })
              .then(() => {
                loading.close()
                this.$message({
                  title: '成功',
                  message: '删除成功',
                  type: 'success',
                  duration: 2000
                })
                this.getList()
              })
              .catch((error) => {
                loading.close()
                reject(error)
              })
          })
        })
        .catch(() => {})
    },
    filtercolumn(scope, item) {
      if (item === 'nd') {
        return scope.row['param2']
      } else if (item === 'EachDistrict') {
        return this.handleRegionList(scope.row)
      }
      return scope.row[item]
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.name = ''
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        craftsmanType: this.activeTab
      }
      if (this.searchshow) {
        query['name'] = this.listQuery.name
      } else {
        query['name'] = this.search.name
        query['sex'] = this.search.sex
        query['politicCountenance'] = this.search.politicCountenance || ''
        query['labelsValue'] = this.search.labelsValue || ''
        query['deptName'] = this.search.deptName || ''

        if (Array.isArray(this.search.ssdq)) {
          query['areaProvince'] = this.search.ssdq[0]
          query['areaCity'] = this.search.ssdq[1]
          query['areaCounty'] = this.search.ssdq[2]
        }
        query['classifyIdValue'] = this.search.classifyIdValue || ''
      }
      return new Promise((resolve, reject) => {
        queryPage(query)
          .then((response) => {
            loading.close()
            this.list = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            reject(error)
            loading.close()
            this.listLoading = false
          })
      })
    },
    handleClose() {},
    handleClick(type) {
      if (type === 'now') {
        this.color = '#e44d42'
        this.archivesList = this.chooseItem.record ? this.chooseItem.record : []
      } else {
        this.color = ''
        this.archivesList = this.chooseItem.deleteRecord ? this.chooseItem.deleteRecord : []
      }
      this.isShowBox = this.archivesList.length < 1
    },
    submitUpload() {
      if (this.$refs['upload'].uploadFiles.length === 0) {
        this.$message.error('请上传文件')
      } else {
        this.loadingUpload = true
        this.uploadHeaders = importSign({ ttsxhost: location.host }, {})
        setTimeout(() => {
          this.$refs.upload.submit()
        }, 1000)
      }
    },
    handleDownload() {
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = '/API-ENTERPRISE-BACKEND/backend/craftsmanLibrary/downloadTemplate' + exportSign({ type: '0' }).paramStr
      link.setAttribute('download', '人物库模版.xls')
      link.setAttribute('target', '_blank')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    },
    handleImport() {
      this.dialogUploadVisible = true
    },
    handleUploadQues() {
      this.dialogUploadVisible = true
    },
    uploadSuccess(data) {
      this.loadingUpload = false
      if (data.code === '200') {
        this.$message({
          message: '导入成功',
          type: 'success'
        })
        this.dialogUploadVisible = false
        this.uploadQuesDialogVisible = false
        this.$refs.upload.clearFiles()
        this.getList()
      } else {
        this.$message.error(data.msg || '网络异常')
        if (data.data.fileid) {
          const link = document.createElement('a')
          link.style.display = 'none'
          link.href = '/API-ENTERPRISE-BACKEND/backend/craftsmanLibrary/downloadCheckFile' + exportSign({ errorId: data.data.fileid }).paramStr
          link.setAttribute('download', '人物库模版.xls')
          link.setAttribute('target', '_blank')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link)
        }
        this.$refs.upload.clearFiles()
        if (data.data) {
          this.uploadErrorList = data.data
          this.dialogUploadErrorTextVisible = true
        }
      }
    },
    uploadError(err) {
      this.loadingUpload = false
      this.$message.error(err || '网络异常')
    },
    handleClosed() {
      this.dialogUploadVisible = false
      this.loadingUpload = false
      this.uploadQuesDialogVisible = false
      this.$refs.upload.clearFiles()
    },

    // 修改排序
    handelUpdateSort() {
      if (this.form.sort === '') {
        this.$message({
          message: '请输入排序值',
          type: 'warning'
        })
        return
      }
      const obj = Object.assign({}, this.form)
      const loading = this.$loading({
        lock: true,
        text: '请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      updateSort(obj).then(res => {
        if (res.data.code === '200') {
          loading.close()
          this.sortDialog = false
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.getList()
        } else {
          loading.close()
          this.$message({
            message: '修改失败',
            type: 'error'
          })
        }
      }).catch(() => {
        loading.close()
      })
    },

    // 强制下发数组修改排序
    handleSort(row) {
      console.log(row, '482')
      this.form.id = row.id
      this.sortDialog = true
    },

    // 取消修改排序
    cancelDialog() {
      this.sortDialog = false
      for (const k in this.form) {
        this.form[k] = ''
      }
    }
  }
}
</script>
<style lang="scss">
@import '@/styles/mixin.scss';

.craftsman-main {
  padding: 10px;
  .el-button + .el-button {
    margin-left: 0;
  }
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            &.el-date-editor input {
              padding-left: 30px;
            }
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }
      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .classify-tab {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;
    .el-tabs__nav-wrap::after {
      display: none;
    }
    .el-tabs__header {
      margin: 0;
    }
  }
  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;
    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }
  .record-container {
    position: relative;
    overflow: visible;
    .btns-container {
      position: absolute;
      right: 0;
      top: -34px;
    }
    h4 {
      margin-top: 0;
      margin-bottom: 10px;
      font-size: 16px;
    }
    p {
      margin: 0;
      white-space: pre-line;
    }

    .classify-tab {
      width: 100%;
      margin: 10px 0;
      padding: 0 10px;
      background-color: #fff;
      display: flex;
      border-radius: 4px;
      .el-tabs__nav-wrap::after {
        display: none;
      }
      .el-tabs__header {
        margin: 0;
      }
    }
  }

  .view-item {
    padding: 10px 5px;
    .view-label {
      font-weight: bold;
      color: #333;
    }
  }
  .isShowBox {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 300px;
    color: #333;
    font-weight: bold;
  }
  .time-line {
    margin-top: 15px;
    max-height: 500px;
    min-height: 300px;
    overflow-y: auto;
    &::-webkit-scrollbar {
      width: 8px; /*对垂直流动条有效*/
      height: 1px; /*对水平流动条有效*/
    }
    /** 滚动条轨道*/
    &::-webkit-scrollbar-track {
      box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
      background-color: white;
      border-radius: 3px;
    }
    /** 滚动条里面小方块*/
    &::-webkit-scrollbar-thumb {
      height: 32px;
      border-radius: 5px;
      box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1);
      background-color: #eaeaea;
    }
    &:hover {
      overflow: auto;
    }
    .el-timeline-item__node {
      left: 5px;
    }
  }
  .cell {
    .el-image {
      width: 100% !important;
      height: auto !important;
    }
  }
  .el-upload__tip {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .upload-demo {
    display: flex;
    flex-direction: column;
    justify-content: center;
    .el-upload-dragger {
      width: 100%;
    }
    .el-upload .el-upload--text {
      display: flex;
      justify-content: center;
    }
  }
}
</style>
